<template>
	<view>
		<navbar name="讲堂详情"></navbar>
		<!-- {{video_details.enableFlag}}---{{vid}} -->
		<!-- 腾讯视频 -->
		<txv-video v-if="video_details.enableFlag == 1" @play="playVideo" @ended="changeTime" :autoplay="true"
			@pause="suspendVideo" :vid="vid" playerid="txv1" :controls="true" @timeupdate="playSchedule">
		</txv-video>

		<!-- 正常视频 -->
		<video id="myVideo" v-if="video_details.enableFlag == 2" :src="new_play_videoUrl" class="video-box"
			@play="playVideo" @pause="suspendVideo" :autoplay="true" @timeupdate="playSchedule"
			:controls="true"></video>
		<!-- 标题 -->
		<view class="video-tittle-box">
			<view class="title-text ellipsis">
				<!-- 糖尿病如何控制并发症的发生？糖尿病如何控制并发症的发生？糖尿病如何控制并发症的发生？ -->
				{{new_play_video}}
			</view>
			<view class="img-boxs" v-if="isCollect" @tap="cancelCollect">
				<image src="http://static.bsyjk.cn/collecticon/D0EE527757AE451FAD36180E4C4F5753.png"
					style="width: 32upx;height: 32upx;" mode=""></image>
			</view>
			<view class="img-boxs" v-if="!isCollect" @tap="collectAdd">
				<image src="http://static.bsyjk.cn/shouchangccc/4C1ECCC725E345D3A250487C3EC6BFF1.png"
					style="width: 32upx;height: 32upx;" mode=""></image>
			</view>
			<button open-type="share" class="img-boxs share-button">
			</button>
		</view>
		<!-- 下方总盒子 -->
		<view class="inferior-box">
			<!-- 课程介绍 -->
			<view class="course-description">
				<view class="course-text">
					课程介绍
				</view>
				<view class="lines"></view>
			<!-- 	<view class="doctor-message">
					<view class="left-box">
						<u-lazy-load border-radius="40" height="80" img-mode="aspectFill"
							:image="video_details.headPic ||'http://static.bsyjk.cn/l/1CED3C4BDCC34BB39367DEAA3A422A70.png'">
						</u-lazy-load>
					</view>
					<view class="right-box" v-if="video_details.sourceType == 2">
						<view class="name-box">
							<text class="name-text">{{video_details.expertName||''}}</text>
							<text class="name-text">{{video_details.expertLevel||''}}</text>
						</view>
						<view class="hospital">
							{{video_details.hospital||''}} <text v-show="video_details.hospital">|</text>
							{{video_details.department||''}}
						</view>
					</view>
					<view class="right-box" v-if="video_details.sourceType == 1">
						<view class="name-box">
							<text class="name-text">{{video_details.source || '暂无'}}</text>
						</view>
					</view>
				</view> -->
				<!-- 医生简介 -->
				<!-- <view class="doctor-synopsis" v-if="video_details.sourceType == 2">
					{{video_details.expertDesc || '暂无专家介绍'}}
				</view> -->
				  <view class="doctor-synopsis" style="margin-top: 20upx;">

							{{video_details.albumDesc}}
				       </view>
			</view>
			<!-- 课程章节 -->
			<view class="course-description">
				<view class="course-text">
					课程章节
				</view>
				<view class="lines"></view>
				<view class="play-video-list-all">
					<view v-for="(item,index) in video_details.videoAlbumDetailVOS" :key="index"
						@tap.stop="cutVideo(index)">
						<view class="play-video-list" v-if="item.choose == true">
							<view class="play-img" v-show="item.play== true">
								<image src="https://bsyjk-pic.bsyjk.cn/l/B91E26F0C1B443708549FE9A18B982B1.gif"
									style="width: 42upx;height: 40upx;" mode=""></image>
							</view>
							<view class="play-img" v-show="item.play==false">
								<image src="http://static.bsyjk.cn/l/6F87BA9269174208B5F658B2247794B8.png"
									style="width: 42upx;height: 40upx;" mode=""></image>
							</view>
							<view class="titles-list text-line">
								<!-- 糖尿病如何控制并发症的发生？ -->
								{{item.videoName}}
							</view>
						</view>
						<view class="play-video-list" v-if="item.choose == false">
							<!--  <view class="">
               第三课
             </view> -->
							<view class="no-titles-list text-line">
								第{{item.videoChapter}}课 {{item.videoName}}
							</view>
						</view>
						<view class="lines"></view>
					</view>
				</view>
			</view>

			<!-- 课程推荐 -->
			<view class="course-description" v-if="false">
				<view class="course-text">
					课程推荐
				</view>
				<view class="lines"></view>
				<view class="course-recommend-box">
					<view class="course-recommend-list" v-for="(item,index) in list" :key="index">
						<view class="course-recommend-top">
							<view class="course-img-box">
								<u-lazy-load border-radius="10" height="186" img-mode="aspectFill"
									image="https://cdn.uviewui.com/uview/swiper/3.jpg">
								</u-lazy-load>
								<view class="video-img-box">
									<image src="https://bsyjk-pic.bsyjk.cn/l/F8C96B4B4CE6440AA0ADD678C455CCA5.png"
										style="width: 40upx;height: 40upx;" mode=""></image>
								</view>
							</view>
							<view class="course-right-box">
								<view class="course-title text-line">
									总是发炎的扁桃体要不要切除？
									总是发炎的扁桃体要不要切除？
								</view>
								<view class="eye-box">
									<view class="eye-img-box">
										<image src="https://bsyjk-pic.bsyjk.cn/l/3016654B38674A31A70E382B2AEDB4BF.png"
											style="width: 44upx;height: 28upx;" mode=""></image>
									</view>
									<view class="eye-number">
										32432
									</view>
								</view>
							</view>
						</view>
						<view class="lines" v-show="index*1+1 != list.length"> </view>
					</view>
				</view>
			</view>

			<view style="height: 100upx;">

			</view>

		</view>

		<view class="loading-box">
			<u-loading :show="loadingone" color="#41ADBA" size="70"></u-loading>
		</view>
		<view v-if="taskStepId != ''&&upPage!='healthBeans'&&task!=1">
			<task :code="code" :taskStepId="taskStepId" :task="task" :bean="bean" :upPage="upPage"></task>
		</view>
		<view v-if="taskStepId != ''&&upPage=='healthBeans'&&task!=1">
			<myTask :code="code" :taskStepId="taskStepId" :task="task" :bean="bean" :upPage="upPage"></myTask>
		</view>
	</view>
</template>

<script>
import uLoading from "@/uview-ui/components/u-loading/u-loading.vue"

import uLazyLoad from "@/uview-ui/components/u-lazy-load/u-lazy-load.vue"

	import task from "./task"
	import myTask from "./myTask"
	export default {
		components: {
			uLoading,
			uLazyLoad,
			task,
			myTask
		},
		data() {
			return {
				bean: '', //健康豆
				taskStepId: '', //任务id
				upPage: '', //上一页
				code: 120, //任务时长
				list: [],
				id: '', //视频id信息
				video_details: [], //video 详细数据
				new_play_video: '', //当前播放的视频名字
				new_play_videoUrl: '', //当前播放的地址
				new_play_videoDuration: '', //当前播放视频总时长
				new_play_videoCurrentTime: '', //当前播放视频进度
				new_play_videoPercentage: '', //当前播放视频百分比
				new_play_videoId: '', //当前播放视频id
				isCollect: false, //是否收藏
				videoIndex: 0, //当前播放视频下标
				lastVideoIndex: '', //上一个播放视频的下标
				loadingone: false, //加载中
				initial_time: '', //视频播放初始位置
				chooseVideoIndex: '', //选中的视频下标
				playVideoIndex: 'a', //播放视频的下标
				InThePlay: false, //当前是否在播放
				tid: '', //当前章节id
				laveNew: false, //是否要离开当前界面 默认未 false
				source: '', //1代表冲最进学习界面进来的  2 代表冲我的收藏界面进来的

				TxvContext: '',
				txvContext: '',
				vid: '',
				readNum: '', //浏览量
				no_permission: false, //是否有权限
				loading_failed: false, //加载失败
			};
		},
		onLoad(e) {
			console.log(e, '205555555')
			if (e.givePoint) {
				this.bean = e.givePoint; //豆
			}
			this.task = e.task;
			console.log(e.stepId, 2122222222222)
			this.taskStepId = e.stepId == undefined ? '' : e.stepId;
			this.upPage = e.page ? e.page : '' //上一页
			this.id = e.id;
			this.tid = e.tid;
			this.source = e.source;
			if (e.tid == '') {
				this.getVideoDetails(e.id)
			} else {
				this.getVideoDetailsAnd(e.id, e.tid)
			}
			wx.showShareMenu({
				withShareTicket: true,
				//设置下方的Menus菜单，才能够让发送给朋友与分享到朋友圈两个按钮可以点击
				menus: ["shareAppMessage", "shareTimeline"]
			})
		},
		mounted() {
			this.videoContext = uni.createVideoContext('myVideo'); //创建视频实例指向video
		},
		onShow() {
			this.new_play_videoDuration = ''; //当前播放视频中市场
			this.new_play_videoCurrentTime = ''; //当前视频播放进度
			this.new_play_videoPercentage = ''; //当前播放视频百分比
		},
		methods: {
			//解析视频
			getVideoUrl() {
				let self = this;
				uni.request({
					url: "https://vv.video.qq.com/getinfo?vids=" + this.vid +
						"&platform=101001&charge=0&otype=json", //仅为示例，并非真实接口地址。
					data: {},
					header: {
						// 'content-type':'application/json'
					},
					success: (res) => {
						let weather = res.data.slice(13);
						weather = weather.slice(0, weather.length - 1)
						weather = JSON.parse(weather)
						let ul = weather.vl.vi;
						if (ul.length > 0) {
							let fn = ul[0].fn;
							let vkey = ul[0].fvkey;
							let uis = ul[0].ul.ui;
							let sources = [];
							if (uis.length > 0) {
								uis.forEach((item, index) => {
									let url = item.url;
									if (/[0-9][0-9]{0,62}(\.[0-9][0-9]{0,62})+\.?/.test(item.url) ==
										false) {
										let source = {
											src: url + fn + "?vkey=" + vkey,
											type: fn.indexOf("mp4") ? "video/mp4" : fn.indexOf(
												"ogg") ? "video/ogg" : "video/unknown"
										};
										sources.push(source);
										// console.log(source,'地址')
									}
								});
							}
							self.new_play_videoUrl = sources[0].src;
							let myVideo = uni.createVideoContext('myVideo')
							setTimeout(() => {
								if (self.initial_time > 4) {
									myVideo.seek(self.initial_time);
								}
							}, 100);
							console.log(self.initial_time, 'myVideo')
						}
					}
				});
			},
			//changeTime
			changeTime(e) {
				const TxvContext = requirePlugin("tencentvideo");
				let txvContext = TxvContext.getTxvContext('txv1') // txv1即播放器组件的playerid值
				if (e.detail.isAd == true) {
					setTimeout(() => {
						txvContext.seek(this.initial_time); //快进到某个时间（直播不支持）
					}, 1000);
					console.log(this.initial_time, '上次播放进度')
				}
				console.log(e.detail.isAd, '事态变更')
			},
			// 完成视频任务
			userTaskStep(taskStepId) {
				let _this = this;
				let fdata = {
					userId: uni.getStorageSync(global.IS_DEV?'USER_DATA_BSY_T':'USER_DATA_BSY_Z').userId,
					taskStepId: taskStepId,
				}
				this.$api.put(global.apiUrls.userTaskStep, fdata)
					.then(res => {
						if (res.data.code == 1000) {
							// let result = res.data.result;
							_this.addBean = true //显示添加健康豆
						} else {
							uni.showToast({
								title: res.data.message,
								icon: "none",
								duration: 2000
							});
						}
					}).catch(err => {})
			},
			//获取视频详情及跳转章节
			getVideoDetailsAnd(id, tid) {
				let _this = this;
				this.$cms.get(global.apiUrls.getVideoDetails + id, {}).then(res => {
					console.log(res.data, '视频详细数据')
					if (res.data.code == 1000) {
						_this.isData = true;
						let tidIndex = 0;
						_this.video_details = res.data.result; //赋值详细信息
						_this.readNum = res.data.result.readNum;
						uni.$emit('views', {
							index: _this.index, //浏览当前页面的下坐标
							readNum: _this.readNum, //浏览量
						});
						_this.video_details.videoAlbumDetailVOS.forEach(function(v, index) {
							if (v.videoId == tid) {
								console.log(index, '当前章节id')
								tidIndex = index;
								_this.videoIndex = index;
							}
						})
						// if (tidIndex == '') { //判断当前章节id为空  选择默认
						// 	tidIndex = 0
						// 	_this.videoIndex = tidIndex;
						// }
						// if (res.data.result.videoAlbumDetailVOS.length > 0) {
						// 	this.new_play_video = res.data.result.videoAlbumDetailVOS[tidIndex]
						// 		.videoName; //赋值当前播放的章节
						// 	this.new_play_videoUrl = res.data.result.videoAlbumDetailVOS[tidIndex]
						// 		.videoUrl; //赋值当前播放的地址
						// 	this.new_play_videoId = res.data.result.videoAlbumDetailVOS[tidIndex]
						// 		.videoId; //赋值当前播放章节id
						// 	this.video_details.videoAlbumDetailVOS[tidIndex].choose = true; //赋值当前未选中状态
						// 	this.isCollect = res.data.result.videoAlbumDetailVOS[tidIndex]
						// 		.collectFlag; //赋值当前播放是否收藏
						// 	this.initial_time = res.data.result.videoAlbumDetailVOS[tidIndex]
						// 		.studyLength; //赋值当前播放视频的进度
						// }
						if (res.data.result.videoAlbumDetailVOS.length > 0) {
							_this.initial_time = res.data.result.videoAlbumDetailVOS[tidIndex]
								.studyLength; //赋值当前播放视频的进度
							_this.new_play_video = res.data.result.videoAlbumDetailVOS[tidIndex]
								.videoName; //赋值当前播放的章节
							_this.new_play_videoId = res.data.result.videoAlbumDetailVOS[tidIndex]
								.videoId; //赋值当前播放章节id
							_this.video_details.videoAlbumDetailVOS[tidIndex].choose = true; //赋值当前未选中状态
							_this.isCollect = res.data.result.videoAlbumDetailVOS[tidIndex]
								.collectFlag == 1?true:false; //赋值当前播放是否收藏
							_this.vid = res.data.result.videoAlbumDetailVOS[tidIndex].vid;
							if (_this.vid != '' && _this.vid != 0 && _this.vid != null && _this.vid != undefined) {
								_this.getVideoUrl();
							} else {
								_this.new_play_videoUrl = res.data.result.videoAlbumDetailVOS[tidIndex]
									.videoUrl; //赋值当前播放的地址
								let myVideo = uni.createVideoContext('myVideo')
								setTimeout(() => {
									if (_this.initial_time > 4) {
										myVideo.seek(_this.initial_time);
									}
								}, 100);
							}

						}
						_this.loadingone = false;
					} else if (res.data.code == 3310) {
						_this.loadingone = false;
						_this.no_permission = true;
						_this.$message.info(res.data.message)
					} else {
						_this.loadingone = false;
						_this.$message.info('加载失败请稍后重试!')
					}
				}).catch(err => {})
			},
			//获取视频详细信息
			getVideoDetails(id) {
				let _this = this;
				this.$cms.get(global.apiUrls.getVideoDetails + id, {}).then(res => {
					console.log(res.data, '视频详细数据')
					if (res.data.code == 1000) {
						this.readNum = res.data.result.readNum;
						uni.$emit('views', {
							index: _this.index, //浏览当前页面的下坐标
							readNum: _this.readNum, //浏览量
						});
						this.isData = true;
						this.video_details = res.data.result; //赋值详细信息
						let lastid = res.data.result.topicId; //赋值上次播放的id
						this.video_details.videoAlbumDetailVOS.forEach(function(v, index) {
							if (v.videoId == lastid) {
								console.log(index, '上次播放章节下标')
								_this.videoIndex = index;
							}
						})
						if (res.data.result.videoAlbumDetailVOS.length > 0) {
							this.initial_time = res.data.result.videoAlbumDetailVOS[_this.videoIndex]
							.studyLength; //赋值当前播放视频的进度
							this.vid = res.data.result.videoAlbumDetailVOS[_this.videoIndex].vid;
							if (_this.vid != '' && _this.vid != 0 && _this.vid != null && _this.vid != undefined) {
								_this.getVideoUrl();
							} else {
								_this.new_play_videoUrl = res.data.result.videoAlbumDetailVOS[_this.videoIndex]
									.videoUrl; //赋值当前播放的地址
								let myVideo = uni.createVideoContext('myVideo')
								setTimeout(() => {
									if (this.initial_time > 4) {
										myVideo.seek(this.initial_time);
									}
								}, 100);
							}
							this.new_play_video = res.data.result.videoAlbumDetailVOS[_this.videoIndex]
							.videoName; //赋值当前播放的章节
							this.new_play_videoId = res.data.result.videoAlbumDetailVOS[_this.videoIndex]
							.videoId; //赋值当前播放章节id
							this.video_details.videoAlbumDetailVOS[_this.videoIndex].choose = true; //赋值当前未选中状态
							this.isCollect = res.data.result.videoAlbumDetailVOS[_this.videoIndex]
							.collectFlag == 1?true:false; //赋值当前播放是否收藏
						}
						_this.loadingone = false;
					} else if (res.data.code == 3310) {
						_this.loadingone = false;
						_this.no_permission = true;
						_this.$message.info(res.data.message)
					} else {
						_this.loadingone = false;
						_this.loading_failed = true;
						_this.$message.info('加载失败请稍后重试!')
					}
					// if (res.data.code == 1000) {
					// 	this.video_details = res.data.result; //赋值详细信息
					// 	let lastid = res.data.result.topicId; //赋值上次播放的id
					// 	console.log(lastid, '2933333333333333333333')
					// 	this.video_details.videoAlbumDetailVOS.forEach(function(v, index) {
					// 		if (v.videoId == lastid) {
					// 			console.log(index, '上次播放章节下标')
					// 			_this.videoIndex = index;
					// 		}
					// 	})
					// 	if (res.data.result.videoAlbumDetailVOS.length > 0) {
					// 		this.new_play_video = res.data.result.videoAlbumDetailVOS[_this.videoIndex]
					// 			.videoName; //赋值当前播放的章节
					// 		this.new_play_videoUrl = res.data.result.videoAlbumDetailVOS[_this.videoIndex]
					// 			.videoUrl; //赋值当前播放的地址
					// 		this.new_play_videoId = res.data.result.videoAlbumDetailVOS[_this.videoIndex]
					// 			.videoId; //赋值当前播放章节id
					// 		this.video_details.videoAlbumDetailVOS[_this.videoIndex].choose = true; //赋值当前未选中状态
					// 		this.isCollect = res.data.result.videoAlbumDetailVOS[_this.videoIndex]
					// 			.collectFlag; //赋值当前播放是否收藏
					// 		this.initial_time = res.data.result.videoAlbumDetailVOS[_this.videoIndex]
					// 			.studyLength; //赋值当前播放视频的进度
					// 	}
					// } else {}
				}).catch(err => {})
			},
			cutVideo(index) {
				this.videoContext.pause(); //暂停视频播放
				let _this = this;
				_this.lastVideoIndex = _this.videoIndex; //赋值上上一个视频的index
				_this.InThePlay = false; //当前不再播放
				_this.videoIndex = index; //当前选中视频的下标
				_this.video_details.videoAlbumDetailVOS.forEach(function(v, index) {
					v.choose = false;
					v.play = false;
				})
				_this.initial_time = _this.video_details.videoAlbumDetailVOS[index].studyLength; //赋值当前播放视频的进度
				_this.video_details.videoAlbumDetailVOS[index].choose = true; //赋值当前未选中状态
				_this.new_play_video = _this.video_details.videoAlbumDetailVOS[index].videoName; //当前播放的视频名字
				_this.vid = _this.video_details.videoAlbumDetailVOS[index].vid; //当前播放的地址
				if (_this.vid != '' && _this.vid != 0 && _this.vid != null && _this.vid != null) {
					_this.getVideoUrl();
				} else {
					_this.new_play_videoUrl = _this.video_details.videoAlbumDetailVOS[index].videoUrl; //当前播放的地址
					let myVideo = uni.createVideoContext('myVideo')
					setTimeout(() => {
						if (this.initial_time > 4) {
							myVideo.seek(this.initial_time);
						}
					}, 100);
				}
				_this.isCollect = _this.video_details.videoAlbumDetailVOS[index].collectFlag == 1?true:false; //赋值当前播放是否收藏
				_this.video_details.videoAlbumDetailVOS[_this.lastVideoIndex].studyLength = this
					.new_play_videoCurrentTime; //赋值上一个播放进度
				console.log(_this.lastVideoIndex, '上个视频下标')
				console.log(this.new_play_videoCurrentTime, '上个视频播放进度')
				console.log(_this.video_details.videoAlbumDetailVOS)
				console.log(_this.new_play_videoCurrentTime, '当前播放进度111')
				if (_this.new_play_videoCurrentTime !== '') {
					this.addPlan(); //请求添加播放进度
				}
			},
			//切换视频
			// cutVideo(index) {
			// 	this.videoContext.pause(); //暂停视频播放
			// 	let _this = this;
			// 	_this.lastVideoIndex = _this.videoIndex; //赋值上上一个视频的index
			// 	_this.InThePlay = false; //当前不再播放
			// 	_this.videoIndex = index; //当前选中视频的下标
			// 	_this.video_details.videoAlbumDetailVOS.forEach(function(v, index) {
			// 		v.choose = false;
			// 		v.play = false;
			// 	})
			// 	_this.video_details.videoAlbumDetailVOS[index].choose = true; //赋值当前未选中状态
			// 	_this.new_play_video = _this.video_details.videoAlbumDetailVOS[index].videoName; //当前播放的视频名字
			// 	_this.vid = _this.video_details.videoAlbumDetailVOS[index].vid; //当前播放的地址
			// 	_this.new_play_videoUrl = _this.video_details.videoAlbumDetailVOS[index].videoUrl; //当前播放的地址
			// 	// _this.new_play_videoUrl = _this.video_details.videoAlbumDetailVOS[index].vid; //当前播放的地址
			// 	_this.isCollect = _this.video_details.videoAlbumDetailVOS[index].collectFlag; //赋值当前播放是否收藏
			// 	_this.initial_time = _this.video_details.videoAlbumDetailVOS[index].studyLength; //赋值当前播放视频的进度
			// 	_this.video_details.videoAlbumDetailVOS[_this.lastVideoIndex].studyLength = this
			// 		.new_play_videoCurrentTime; //赋值上一个播放进度
			// 	console.log(_this.lastVideoIndex, '上个视频下标')
			// 	console.log(this.new_play_videoCurrentTime, '上个视频播放进度')
			// 	console.log(_this.video_details.videoAlbumDetailVOS)
			// 	console.log(_this.new_play_videoCurrentTime, '当前播放进度111')
			// 	if (_this.new_play_videoCurrentTime !== '') {
			// 		this.addPlan(); //请求添加播放进度
			// 	}
			// },
			//向服务器添加播放进度
			addPlan() {
				let _this = this;
				let studyStatus = 0; //学习状态（1：已完成；0：未完成）
				if (this.new_play_videoPercentage >= 98) {
					studyStatus = 1;
				}
				_this.$cms.post(global.apiUrls.addVideoStudy, {
						studyLength: Math.floor(_this.new_play_videoCurrentTime), //学习时长
						studyProgress: _this.new_play_videoPercentage, //学习进度 30%
						studyStatus: studyStatus, //学习状态（1：已完成；0：未完成）
						topicId: _this.new_play_videoId, //当前学习视频id
						topicType: 2, //类型1：文章2：讲堂3：商品4：帖子
						userId: global.userInfo.adviserId, //当前用户id
						videoLength: Math.floor(_this.new_play_videoDuration), //总时长
					})
					.then(res => {
						console.log(res.data, '收藏章节')
						if (res.data.code == 1000) {
							_this.new_play_videoId = _this.video_details.videoAlbumDetailVOS[_this.videoIndex]
								.videoId; //赋值当前播放章节id
							console.log(_this.new_play_videoCurrentTime, '播放进度')
							_this.new_play_videoDuration = ''; //当前播放视频中市场
							_this.new_play_videoCurrentTime = ''; //当前视频播放进度
							_this.new_play_videoPercentage = ''; //当前播放视频百分比
							//当离开当前界面的时候调用上一个也面的值
							if (_this.laveNew == true && _this.tid !== '' && _this.source == 1) {
								console.log('已经走到了当前数据里面')
								let pages = getCurrentPages(); //当前页面栈
								let beforePage = pages[pages.length - 1]; //指定调用页面为上个页面
								beforePage.$vm.onceGetLatelyStudy() //getData 是你要调用上个页面的方法，微信小程序不需要用 $vm
							}
						} else {}
					}).catch(err => {
						this.loadingone = false;
						console.log(res)
					})
			},
			//点击开始时触发
			playVideo(e) {
				this.video_details.videoAlbumDetailVOS[this.videoIndex].play = true;
				this.InThePlay = true;
				console.log(this.videoIndex, '当前视频下标')
				console.log(this.video_details.videoAlbumDetailVOS, '当前数据')
				console.log(this.initial_time, '新视频播放进度') //
			},
			//点击暂停时触发
			suspendVideo(e) {
				this.video_details.videoAlbumDetailVOS[this.videoIndex].play = false;
				this.InThePlay = false;
			},
			//播放进度
			playSchedule(e) {
				if (this.InThePlay == true) {
					this.new_play_videoDuration = e.detail.duration; //当前播放视频总时长
					this.new_play_videoCurrentTime = e.detail.currentTime; //当前视频播放进度
					this.new_play_videoPercentage = Math.floor(((e.detail.currentTime) / (e.detail.duration)) * 100);
				}
			},
			//文章收藏
			collectAdd() {
				this.loadingone = true;
				this.$cms.post(global.apiUrls.articleCollects, {
						topicId: this.video_details.videoAlbumDetailVOS[this.videoIndex].videoId, //视频章节id
						topicType: 2, //收藏类型1：文章2：讲堂3：商品4：帖子
					})
					.then(res => {
						console.log(res.data, '收藏章节')
						if (res.data.code == 1000) {
							this.loadingone = false;
							this.isCollect = true;
							this.video_details.videoAlbumDetailVOS[this.videoIndex].collectFlag = 1;
							this.$message.info('收藏成功')
						} else {
							this.loadingone = false;
							this.$message.info('收藏失败')
						}
					}).catch(err => {
						this.loadingone = false;
						this.$message.info('收藏失败')
						console.log(res)
					})
			},
			//取消收藏
			cancelCollect() {
				this.loadingone = true;
				this.$cms.delete(global.apiUrls.articleCollects, {
						topicId: this.video_details.videoAlbumDetailVOS[this.videoIndex].videoId, //文章id
						topicType: 2, //收藏类型1：文章2：讲堂3：商品4：帖子
					})
					.then(res => {
						console.log(res.data, '取消收藏章节')
						if (res.data.code == 1000) {
							this.loadingone = false;
							this.isCollect = false;
							this.video_details.videoAlbumDetailVOS[this.videoIndex].collectFlag = 0;
							this.$message.info('取消成功')
						} else {
							this.loadingone = false;
							this.$message.info('取消失败')
						}
					}).catch(err => {
						this.loadingone = false;
						this.$message.info('取消失败')
						console.log(res)
					})
			},
		},
		onUnload() {
			this.videoContext.pause(); //暂停视频播放
			this.laveNew = true; //赋值当前离开页面
			if (this.new_play_videoCurrentTime !== '') {
				this.addPlan(); //请求添加播放进度
			}
			if (this.source == 2 && this.isCollect == false) {
				console.log('当前界面取消了收藏')
				let pages = getCurrentPages(); //当前页面栈
				let beforePage = pages[pages.length - 2]; //指定调用页面为上个页面
				beforePage.$vm.onceGetLatelyStudy() //getData 是你要调用上个页面的方法，微信小程序不需要用 $vm
			}
			this.lastVideoIndex = '';
			console.log('页面销毁了')
		},
        addPointAndGrade(){
          if(global.userInfo.shopUid){
            this.$https.post(global.apiUrls.addPointAndGrade+"/"+global.userInfo.shopUid+"/SHARE_CONTENT").then(res => {
               console.info(res,"分享增加积分和成长值")
            })
          }
        },
		//发送给朋友
		onShareAppMessage(res) {
              this.addPointAndGrade();
			let id = this.id, //视频id
				imageUrl = this.video_details.albumCoverUrl; //封面
			return {
				title: '欢迎观看',
				type: 0,
				path: '/pages/tab/home?id=' + id + '&type=4',
				summary: "",
				imageUrl: imageUrl
			}
		},
	}
</script>

<style lang="scss" scoped>
	.video-box {
		width: 750upx;
		height: 414upx;
	}

	//标题
	.video-tittle-box {
		width: 750upx;
		height: 108upx;
		background-color: #FFFFFF;
		display: flex;
		align-items: center;
		padding: 0upx 24upx;
		justify-content: space-between;

		.title-text {
			width: 558upx;
		}

		.img-boxs {
			width: 32upx;
			height: 32upx;
		}

		.share-button {
			width: 32upx;
			height: 32upx;
			background: url(http://static.bsyjk.cn/fenxiangccc/38355CE4AA5B445E9BC266890F8F0048.png)no-repeat;
			background-size: 32upx 32upx;
		}
	}

	//下方总盒子
	.inferior-box {
		background-color: #F5F5F5;
		padding: 30upx 24upx;

		// 课程介绍
		.course-description {
			border-radius: 16upx;
			background-color: #FFFFFF;
			margin-bottom: 30upx;

			.course-text {
				width: 100%;
				height: 88upx;
				line-height: 88upx;
				color: #000000;
				padding: 0upx 24upx;
				font-size: 30upx;
				font-weight: 500;
			}

			.lines {
				width: 100%;
				height: 1upx;
				background-color: #EEEEEE;
			}

			//视频推荐
			.course-recommend-box {
				padding: 0upx 24upx;

				.course-recommend-list {
					.course-recommend-top {
						padding: 30upx 0upx;
						display: flex;
						justify-content: space-between;

						.course-img-box {
							width: 332upx;
							height: 186upx;
							position: relative;

							.video-img-box {
								position: absolute;
								width: 40upx;
								height: 40upx;
								right: 10upx;
								bottom: 10upx;
							}
						}

						.course-right-box {
							width: 300upx;

							.course-title {
								width: 300upx;
								height: 84upx;
								font-size: 30upx;
								font-family: PingFang-SC-Medium, PingFang-SC;
								font-weight: 500;
								color: #333333;
								line-height: 42upx;
							}

							.eye-box {
								display: flex;
								align-items: center;
								margin-top: 74upx;

								.eye-img-box {
									width: 44upx;
									height: 28upx;
								}

								.eye-number {
									font-size: 26upx;
									font-family: PingFangSC-Regular, PingFang SC;
									font-weight: 400;
									color: #999999;
									line-height: 37upx;
									margin-left: 10upx;
								}

							}

						}
					}
				}

			}

			//视频播放列表
			.play-video-list-all {
				padding: 0upx 28upx;

				.play-video-list {
					padding: 24upx 0upx;
					display: flex;
					align-items: center;
					justify-content: space-between;

					.play-img {
						width: 42upx;
						height: 40upx;
					}

					.titles-list {
						width: 550upx;
						font-size: 30upx;
						font-family: PingFangSC-Regular, PingFang SC;
						font-weight: 400;
						color: #2EA7E0;
						line-height: 42upx;
						max-height: 84upx;
					}

					.no-titles-list {
						width: 550upx;
						font-size: 30upx;
						font-family: PingFangSC-Regular, PingFang SC;
						font-weight: 400;
						color: #333333;
						line-height: 42upx;
						max-height: 84upx;
					}
				}
			}

			//医生信息
			.doctor-message {
				display: flex;
				align-items: center;
				padding: 30upx 24upx;

				.left-box {
					width: 80upx;
					height: 80upx;
				}

				.right-box {
					margin-left: 20upx;

					.name-box {
						.name-text {
							font-size: 30upx;
							font-family: PingFangSC-Regular, PingFang SC;
							font-weight: 400;
							color: #333333;
							line-height: 42upx;
							margin-right: 30upx;
						}
					}

					.hospital {
						font-size: 24upx;
						font-family: PingFangSC-Regular, PingFang SC;
						font-weight: 400;
						color: #333333;
						line-height: 33upx;
					}
				}
			}

			//医生简介
			.doctor-synopsis {
				font-size: 26upx;
				font-family: PingFangSC-Regular, PingFang SC;
				font-weight: 400;
				color: #333333;
				line-height: 37upx;
				padding: 0upx 24upx 30upx;
			}
		}
	}
</style>
